# 阻塞式

import os
import random
import time
from multiprocessing import Pool


# 非阻塞式进程
def task(task_name):
    print("开始做任务了!", task_name)
    start = time.time()
    time.sleep(random.random() * 2)
    end = time.time()
    print("完成任务用时:{}， pid={}".format((end - start), os.getpid()))

    # return "完成任务用时:{}， pid={}".format((end - start), os.getpid())


container = []


def callback_func(n):
    print('----->', n)
    container.append(n)


if __name__ == '__main__':
    pool = Pool(5)
    for i in range(8):
        pool.apply(task, args=('task' + str(i),))

    # pool.close()  # 添加任务结束
    # pool.join()
    print("over@@@@")
    print(container)
